import Vue from 'vue';
import VueI18n from 'vue-i18n';
import Element from 'element-ui'
import * as lang_cn from '../assets/lang/cn';
import * as lang_en from '../assets/lang/en';
import * as lang_ina from '../assets/lang/ina';
import en from 'element-ui/lib/locale/lang/en'
import zh from 'element-ui/lib/locale/lang/zh-CN'


Vue.use(VueI18n);

const messages = {
    en: Object.assign(lang_en, en),
    ina: Object.assign(lang_ina, en),
    zh: Object.assign(lang_cn, zh)
};

let locale = localStorage.getItem('lang')||'zh'
export  const i18n = new VueI18n({
    locale: locale,  // set locale
    messages  // set locale messages
});

/* widuu 格式化日期方法 */
Date.prototype.Format = function (fmt) {
    var o = {
        "m+": this.getMonth() + 1,
        "d+": this.getDate(),
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

Vue.use(Element, {
    i18n: (key, value) => i18n.t(key, value)
})